package com.etc.emsys.controller.emp;

import com.etc.emsys.controller.BaseContrller;
import com.etc.emsys.controller.BaseMenuController;
import com.etc.emsys.dao.emp.DeptDao;
import com.etc.emsys.dao.emp.EmpDao;
import com.etc.emsys.domain.DeptPojo;
import com.etc.emsys.domain.EmpPojo;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;

import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

public class EmpAddController extends BaseMenuController {

    @FXML
    TextField empno;
    @FXML
    TextField ename;
    @FXML
    ComboBox deptcombox;

    @Override
    public void initialize(URL location, ResourceBundle resources) {

        DeptDao dao = new DeptDao();
        List<DeptPojo> list = dao.selectAllDept();
        deptcombox.setItems(FXCollections.observableList(list));

    }

    public void reset() {
        empno.setText("");
        ename.setText("");
        deptcombox.setValue("");
    }
    public void add() {
        EmpPojo input = new EmpPojo();

        input.setEmpno(Integer.parseInt(empno.getText()));
        input.setEname(ename.getText());
        input.setDname(String.valueOf(deptcombox.getValue()));
        EmpDao dao = new EmpDao();
        dao.insertEmp(input);
        Alert alert = new Alert(Alert.AlertType.INFORMATION, "更新成功");
        alert.showAndWait();
        transformNon("../../view/emp/main.fxml", "更新成功", null, ename.getScene());
    }
}
